package com.trkj.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.DeptDAO;
import com.trkj.dao.EmpDAO;
import com.trkj.pojo.Dept;
import com.trkj.pojo.Emp;
import com.trkj.vo.TransferVo;

@Service
@Transactional
public class TransferService {
	@Autowired
	DeptDAO deptDAO;
	@Autowired
	EmpDAO empDAO;
	public TransferVo transferVo(Integer empId) {
		try {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			Emp emp = empDAO.findOne(empId);
			TransferVo transferVo = new TransferVo();
			Date date = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
			int a = date.getYear()+1900;
			int b = date.getMonth()+1;
			int c = date.getDate();
			transferVo.setTransferUptime(a+"-"+b+"-"+c);
			transferVo.setLunchPeople(emp.getEmpId());
			return transferVo;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
		
		
	}
	
	/**
	 * 查询所有部门的信息，id和name封装到map
	 * @return
	 */
	public List<Map<String, Object>> findAllDept(){
		List<Dept> list = deptDAO.findAll();
		List<Map<String, Object>> maps = new ArrayList<>();
		if (list != null) {
			for(Dept dept : list) {
				Map<String, Object> map = new HashMap<>();
				map.put("deptId", dept.getDeptId());
				map.put("deptName", dept.getDeptName());
				maps.add(map);
			}
		}
		return maps;
	}
	/**
	 * 根据员工编号查询所有部门的信息，id和name封装到map
	 * @return
	 */
	public Map<String, Object> findOneDept(Integer empId){
		Emp emp = empDAO.findOne(empId);
		Map<String, Object> map = new HashMap<>();
		if (emp != null) {
			map.put("deptId", emp.getDept().getDeptId());
			map.put("deptName", emp.getDept().getDeptName());
		}
		return map;
	}
	/**
	 * 查询所有的员工信息，id和name封装到map
	 * @return
	 */
	public List<Map<String, Object>> findAll_emp_combobox() {
		List<Emp> findAll = empDAO.findAll();
		List<Map<String, Object>> list = new ArrayList<>();
		if (findAll != null) {
			for(Emp emp : findAll) {
				Map<String, Object> map = new HashMap<>();
				map.put("empId", emp.getEmpId());
				map.put("empName", emp.getEmpName());
				list.add(map);
			}
		}
		return list;
	}
}
